package com.gin.supermarket_inventory_system.inventory.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.gin.database.service.MyService;
import com.gin.supermarket_inventory_system.inventory.entity.SettlementDayPo;

import java.util.List;

/**
 *
 * @since : 2023/10/14 15:28
 * @author : ginstone
 * @version : v1.0.0
 **/
public interface SettlementDayService extends MyService<SettlementDayPo> {
    /**
     * 执行结算
     */
    void settle();

    /**
     * 按月份统计各字段总和
     * @param start 开始月
     * @param end 结束月
     * @return 总和
     */
    default List<SettlementDayPo> sumGroupByMonth(String start, String end) {
        final QueryWrapper<SettlementDayPo> qw = new QueryWrapper<>();
        qw.select(
                        "LEFT(date,7) as date"
                        , "sum(total_price_sell) as total_price_sell"
                        , "sum(count_sell) as count_sell"
                        , "sum(total_price_cancel) as total_price_cancel"
                        , "sum(count_cancel) as count_cancel"
                        , "sum(total_price_purchase) as total_price_purchase"
                        , "sum(count_purchase) as count_purchase"
                        , "sum(total_price_reject) as total_price_reject"
                        , "sum(count_reject) as count_reject"
                )
                .between("date", start, end)
                .groupBy("date");

        return list(qw);
    }
}